package com.smile.config;

import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.Map;

@Configuration
//@RefreshScope
public class FeisuanNacosConfiguration {

//    @Value("${server.servlet.context-path:}")
//    private String contextPath;

    @Autowired
    private NacosDiscoveryProperties nacosDiscoveryProperties;

    @PostConstruct
    public void customizeNacosMetadata() {
        Map<String, String> metadata = nacosDiscoveryProperties.getMetadata();
        // 只在 key 不存在时追加，避免覆盖用户已有配置
        metadata.putIfAbsent("route.enable", "true");
        metadata.putIfAbsent("route.prefix", "1");
//        metadata.putIfAbsent("route.path", contextPath);
    }
}